function [ X, best_k, best_t, closure, converge ] = ZeidelMethod2( A, b, eps, max, t_min, t_max)
N = size(A, 1);
best_t = 0;
best_k =Inf;
step = (t_max - t_min) / 1000;

fileId = fopen('zeidel_report.txt', 'w');

for t = t_min : step : t_max
    conv = true;
    if (t == 0)
        continue;
    end;
    B = eye(N) - t * A;
    c = t * b;
    
    useMax = false;
    norm_no = 1;
    if (norm(B, norm_no) > 1)
        norm_no = Inf;
        if (norm(B, norm_no) > 1)
            norm_no = 1;
            useMax = true;
        end;
    end;
    
    if (~useMax)
        n1 = norm(B, 1);
        n2 = norm(B, Inf);
        wait = 1;
    end;
        
    x = c;
    p = zeros(size(x), 1); 
    k = 0;
    while (true)
        for i = 1 : size(A, 1)
            var = 0;
            for j = 1 : size(A, 2)
                if (j ~= i)
                    var = var + B(i, j) * x(j);
                end;
            end;
            p(i) = x(i);
            x(i) = (c(i) + var) ; 
        end;
        k = k + 1;
        for i = 1 : size(x)
           if (isnan(x(i)) || isinf(x(i)))
               conv = false;
               break;
           end;
        end;
        if (useMax && k >= max || ~conv)
            conv = false;
            break;
        end;
        if (norm(x - p, norm_no) <= eps || k == max + 1)
            break;
        end; 
        
    end;
    
    fprintf(fileId, '\tX when t = %.4f, k = %d norm = %.4f\n', t, k, norm(A*x-c, norm_no));
    if (conv)
        fprintf(fileId, '%.4f\n', x);
    else
        fprintf(fileId, 'Converge == false');
    end;
    fprintf(fileId, '\n\n');
    
    if (k < best_k && conv)
        best_k = k;
        best_t = t;
        X = x;
    end;
    
end;

converge = best_k < Inf;
if (converge)
    closure = A * x - b;
else
    closure = Inf;
    X = Inf;
end;

fclose(fileId);



end

